<template>
  <t-dialog :header="`${header}-标准详情`" :visible.sync="visible" :onClose="closeDialog" :closeOnOverlayClick="false"
    :confirmBtn="null" width="80%" top="5%">
    <t-tabs placement="left" size="medium" v-model="stepValue">
      <t-tab-panel value="1" label="建议表详情">
        <!-- <t-sticky-tool
          :style="{ position: 'absolute', overflow: 'hidden',zIndex: 1000 }"
          :offset="[-40, -20]"
          @click="createPDF(1)"
        >
          <t-sticky-item  style="width: 80px" label="导出PDF" >
            <template #icon>
              <t-icon name="file-pdf"></t-icon>
            </template>
</t-sticky-item>
</t-sticky-tool> -->
        <suggest-detail :obj-id="objId"></suggest-detail>
      </t-tab-panel>
      <t-tab-panel value="2" label="申报表详情">
        <!-- <t-sticky-tool :style="{ position: 'absolute', overflow: 'hidden', zIndex: 1000 }" :offset="[-40, -20]"
          @click="createPDF(2)">
          <t-sticky-item style="width: 80px" label="导出PDF">
            <template #icon>
              <t-icon name="file-pdf"></t-icon>
            </template>
          </t-sticky-item>
        </t-sticky-tool> -->
        <apply-detail v-if="openSBB" :obj-id="objId"></apply-detail>
        <div v-else
          style="height: 100%;display: flex;justify-content: center;align-items: center;font-weight: bold;font-size: 50px;color: #ccc;">
          待申报表...</div>
      </t-tab-panel>
      <t-tab-panel value="3" label="征求意见详情">
        <!-- <t-sticky-tool :style="{ position: 'absolute', overflow: 'hidden', zIndex: 1000 }" :offset="[-40, -20]"
          @click="createPDF(3)">
          <t-sticky-item style="width: 80px" label="导出PDF">
            <template #icon>
              <t-icon name="file-pdf"></t-icon>
            </template>
          </t-sticky-item>
        </t-sticky-tool> -->
        <opinion-detail v-if="openYJB" :obj-id="objId"></opinion-detail>
        <div v-else
          style="height: 100%;display: flex;justify-content: center;align-items: center;font-weight: bold;font-size: 50px;color: #ccc;">
          待征求意见处理汇总表...</div>
      </t-tab-panel>
      <t-tab-panel value="4" label="报审表详情">
        <!-- <t-sticky-tool v-if="openBSB" :style="{ position: 'absolute', overflow: 'hidden', zIndex: 1000 }"
          :offset="[-40, -20]" @click="createPDF(4)">
          <t-sticky-item style="width: 80px" label="导出PDF">
            <template #icon>
              <t-icon name="file-pdf"></t-icon>
            </template>
          </t-sticky-item>
        </t-sticky-tool> -->
        <report-detail :showPhone="showPhone" v-if="openBSB" :obj-id="objId"></report-detail>
        <div v-else
          style="height: 100%;display: flex;justify-content: center;align-items: center;font-weight: bold;font-size: 50px;color: #ccc;">
          待报审表...</div>
      </t-tab-panel>
      <t-tab-panel value="5" label="报批表详情">
        <submit-detail v-if="openBPB" :obj-id="objId"></submit-detail>
        <div v-else
          style="height: 100%;display: flex;justify-content: center;align-items: center;font-weight: bold;font-size: 50px;color: #ccc;">
          待报批表...</div>
      </t-tab-panel>
    </t-tabs>
  </t-dialog>
</template>

<script>
import suggestDetail from "../../suggest/components/suggest-detail.vue";
import applyDetail from "../../apply/components/apply-detail.vue";
import opinionDetail from "../../opinion/components/opinion-detail.vue";
import reportDetail from "../../report/components/report-detail.vue";
import submitDetail from "../../submit/components/submit-detail.vue";


export default {
  name: "standard-detail-dialog",
  components: {
    suggestDetail,
    applyDetail,
    opinionDetail,
    reportDetail,
    submitDetail
  },
  props: {
    objId: [String, Number],
    header: String,
    tabDefaultValue: {
      type: String,
      default: '1'
    },
    showPhone: {
      type: Boolean,
      default: false
    }
  },
  data () {
    return {
      visible: true,
      stepValue: this.tabDefaultValue,
      openSBB: false,
      openYJB: false,
      openBSB: false,
      openBPB: false,
    }
  },
  created () {
    this.checkSBB();
    this.checkYJB();
    this.checkBSB();
    this.checkBPB();
  },
  methods: {
    createPDF (type) {
      const instance = this.$loading({
        fullscreen: true,
        attach: 'body',
        preventScrollThrough: false,
      });

      // if(type===1){
      //   this.$api.bzh.standard.suggestPdf(this.objId).then(response => {
      //     window.open(response.data.fullFilePath, '_blank')
      //     instance.hide();
      //   }).catch((e) => {
      //     instance.hide();
      //     this.$message.error(e.toString());
      //   });
      // }
      let promise = null;
      if (type === 1) {
        promise = this.$api.bzh.standard.suggestPdf(this.objId)
      } else if (type === 2) {
        promise = this.$api.bzh.standard.createPdfByWindows(this.objId)
      } else if (type === 3) {
        promise = this.$api.bzh.opinion.createPdfByWindows(this.objId)
      } else if (type === 4) {
        promise = this.$api.bzh.report.createPdfByWindows(this.objId)
      }

      if (promise) {
        promise.then(response => {
          window.open(response.data.fullFilePath, '_blank')
          instance.hide();
        }).catch((e) => {
          instance.hide();
          this.$message.error(e.toString());
        });
      } else {
        console.log("promise is null")
      }


    },
    checkBSB () {
      this.$api.bzh.report.getBySuggestId(this.objId).then(response => {
        if (response.data) {
          this.openBSB = true
        }
      }).catch((e) => {
        this.$message.error(e.toString());
      });
    },
    checkBPB () {
      this.$api.bzh.submit.getBySuggestId(this.objId).then(response => {
        if (response.data) {
          this.openBPB = true
        }
      }).catch((e) => {
        this.$message.error(e.toString());
      });
    },
    checkYJB () {
      this.$api.bzh.opinion.getBySuggestId(this.objId).then(response => {
        if (response.data) {
          this.openYJB = true
        }
      }).catch((e) => {
        this.$message.error(e.toString());
      });
    },
    checkSBB () {
      this.$api.bzh.standard.getApplyBySuggestId(this.objId).then(response => {
        if (response.data) {
          this.openSBB = true
        }
      }).catch((e) => {
        this.$message.error(e.toString());
      });
    },
    checkDJ () {
      this.$api.bzh.register.getByLocalId(this.objId).then(response => {
        if (response.data) {
          this.openDJ = true
        }
      }).catch((e) => {
        this.$message.error(e.toString());
      });
    },
    checkBS () {
      this.$api.bzh.report.getByLocalId(this.objId).then(response => {
        if (response.data) {
          this.openBS = true
        }
      }).catch((e) => {
        this.$message.error(e.toString());
      });
    },
    closeDialog () {
      this.$emit("update:visible", false);
    },
  }
}
</script>

<style lang="less" scoped>
.t-tab-panel {
  padding: 10px;
  height: 65vh;
  overflow: scroll;
}
</style>
